package com.css.fxfzypg.modules.model.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.model.entity.Casualty;
import com.css.fxfzypg.modules.model.entity.IntensityAttenuation;
import com.css.fxfzypg.modules.model.service.IntensityAttenuationService;
import com.css.fxfzypg.modules.model.to.CasualtyTO;
import com.css.fxfzypg.modules.model.vo.CasualtyVO;
import com.css.fxfzypg.modules.model.vo.IntensityAttenuationVO;
import com.css.fxfzypg.util.PlatformPageUtils;
import com.css.fxfzypg.util.ResponseCreator;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.text.ParseException;
import java.util.Map;

/**
 * @author Dbj
 * @date 2022年10月05日  14:01
 * 地震烈度衰减关系模型
 */
@RestController
@Validated
@RequestMapping("/intensity")
public class IntensityAttenuationController {

    @Resource
    private IntensityAttenuationService intensityAttenuationService;

    /***
     * 地震烈度衰减关系模型列表分页查询
     * @param vo
     */
    @GetMapping("/page")
    public RestResponse getPage(IntensityAttenuationVO vo, HttpServletRequest request){
        int curPage = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int pageSize=Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        Map<String,Object> page=intensityAttenuationService.getPage(vo,curPage,pageSize);
        return ResponseCreator.createSuccessResponse(page,"查询成功!");
    }

    /***
     * 地震烈度衰减关系模型列表分页查询（地震现场灾害系统调用）
     * @param vo
     */
    @GetMapping("/pageForXczh")
    public RestResponse getPageForXczh(IntensityAttenuationVO vo, HttpServletRequest request){
        int curPage = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int pageSize=Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        vo.setModelName(request.getParameter("modelName"));
        vo.setProvince(request.getParameter("province"));
        vo.setCity(request.getParameter("city"));
        Map<String,Object> page=intensityAttenuationService.getPageForXczh(vo,curPage,pageSize);
        return ResponseCreator.createSuccessResponse(page,"查询成功!");
    }

    /***
     * 地震烈度衰减关系模型根据模型id查询信息
     * @param id
     */
    @GetMapping("/getModelById")
    public RestResponse getModelById(@NotBlank(message="模型id不能为空") @RequestParam("id") String id){
        IntensityAttenuation model = intensityAttenuationService.getModelById(id);
        return ResponseCreator.createSuccessResponse(model);
    }

    /***
     *  地震烈度衰减关系模型id查询信息用于复制信息回显
     * @param id
     */
    @GetMapping("/getModelByIdForCopy")
    public RestResponse getModelByIdForCopy(@NotBlank(message="模型id不能为空") @RequestParam("id") String id){
        IntensityAttenuation model = intensityAttenuationService.getModelByIdForCopy(id);
        return ResponseCreator.createSuccessResponse(model);
    }

    /***
     * 地震烈度衰减关系模型-用于复制保存
     * @param intensityAttenuation
     */
    @PostMapping("/save")
    public RestResponse saveIntensityAttenuation(@Valid @RequestBody IntensityAttenuation intensityAttenuation) throws ParseException {
        intensityAttenuationService.save(intensityAttenuation);
        return ResponseCreator.createSuccessResponse("","保存成功");
    }

    /***
     * 地震烈度衰减关系模型-修改
     * @param intensityAttenuation
     */
    @PostMapping("/update")
    public RestResponse update(@Valid @RequestBody IntensityAttenuation intensityAttenuation){
        intensityAttenuationService.update(intensityAttenuation);
        return ResponseCreator.createSuccessResponse("","保存成功");
    }

    /***
     * 地震烈度衰减关系模型-删除
     * @param vo
     */
    @PostMapping("/delete")
    public RestResponse delete(@RequestBody IntensityAttenuationVO vo){
        intensityAttenuationService.delete(vo.getId());
        return ResponseCreator.createSuccessResponse("","删除成功");
    }
}
